<?php

declare(strict_types=1);

namespace App\WorkContact\Controller\Dashboard;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Common\Middleware\DashboardAuthMiddleware;
use App\WorkContact\Logic\IndexLogic;
use Base\Controller\AbstractController;
use Base\Constants\ErrorCode;
use Base\Exception\CommonException;

/**
 * 客户列表.
 *
 * Class Index
 * @Controller
 */
class Index extends AbstractController
{
    /**
     * @Inject
     * @var IndexLogic
     */
    protected $indexLogic;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class),
     * })
     * @RequestMapping(path="/dashboard/workContact/index", methods="GET")
     */
    public function handle()
    {
        $corp_id = $this->request->input('userInfo.corp_id');
        ## 判断用户绑定企业信息
        if (! isset($corp_id)) {
            throw new CommonException(ErrorCode::INVALID_PARAMS, '未选择登录企业，不可操作');
        }

        //接收参数
        $params = $this->request->inputs(
            [
                'keyWords', 'remark', 'fieldId', 'fieldType', 'fieldValue', 'gender', 'addWay', 'roomId', 'groupNum',
                'employeeId', 'startTime', 'endTime', 'businessNo', 'current', 'size',
            ],
            [
                'current' => 1, 'size' => 20,
            ]
        );
        $params['corpId'] = $corp_id;
        $params['page'] = intval($params['current']);
        $params['perPage'] = intval($params['size']);
        return $this->indexLogic->handle($params);
    }
}
